package com.example.demo.utils;

import org.openqa.selenium.chrome.ChromeDriver;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.bind.Element;
import java.util.List;
import java.util.concurrent.TimeUnit;

@RestController
public class seleniumUtil {
    private static ChromeDriver browser;

    public void openBrowser() {
        System.setProperty("webdriver.chrome.driver","D:/chromedriver.exe");
        browser = new ChromeDriver();
        browser.manage().timeouts()
                .implicitlyWait(10, TimeUnit.SECONDS);
        browser.get("http://www.baidu.com");
        browser.findElementById("kw").sendKeys("优化厂家");
        browser.findElementById("su").click();
//        getpage();
    }
    public void getpage(){
//        List<Element> result = (List<Element>) browser.findElementByClassName("result");
//        for (Element item : result){
//            System.err.println(item);
//        }
    }
    public static void closeBrowser() {
        browser.quit();
    }
}
